package com.biaobiaoqi.scoreanalysis.serviceImpl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biaobiaoqi.scoreanalysis.exception.DuplicateExaminationException;
import com.biaobiaoqi.scoreanalysis.hibernate.bean.Examination;
import com.biaobiaoqi.scoreanalysis.service.IClazzTypeService;
import com.biaobiaoqi.scoreanalysis.service.IExaminationService;
import com.biaobiaoqi.scoreanalysis.service.ISchoolyearService;
import com.biaobiaoqi.scoreanalysis.util.SchoolType;
 
public class ExaminationServiceImpl extends DaoServiceImpl<Examination>
		implements IExaminationService {
	@Resource
	ISchoolyearService schoolyearService;
	@Resource
	IClazzTypeService clazzTypeService;
	@Override
	public void addExamination(String name, Date date, int schoolYearId, int clazzTypeId, SchoolType schoolType)
			throws DuplicateExaminationException {
 		Examination examination = new Examination();
		examination.setDate(date);
		examination.setName(name);
		examination.setClazzType(clazzTypeService.findClazzType(clazzTypeId));
		examination.setSchoolYear(schoolyearService.findSchoolYear(schoolYearId));
		examination.setSchoolType(schoolType);
		getDao().create(examination);
	}

	@Override
	public List<Examination> ListAllExamination(int start, int number) {
		return getDao().queryList("from Examination e order by e.date desc", start, number);
	}

	@Override
	public List<Examination> ListAllExamination() {

		return getDao().queryList("from Examination e order by e.date desc");
	}
 
	public ISchoolyearService getSchoolyearService() {
		return schoolyearService;
	}

	public void setSchoolyearService(ISchoolyearService schoolyearService) {
		this.schoolyearService = schoolyearService;
	}

	public IClazzTypeService getClazzTypeService() {
		return clazzTypeService;
	}

	public void setClazzTypeService(IClazzTypeService clazzTypeService) {
		this.clazzTypeService = clazzTypeService;
	}

	@Override
	public void deleteExamination(int examId) {

		getDao().delete(findExamination(examId));
	}

	public Examination findExamination(int examId) {
 		return getDao().findById(Examination.class, examId);
	}

}
